<template>
	<view class="Login">
		<u-toast ref="uToast"></u-toast>
		<u-navbar leftIcon=" " title=" " :placeholder="true"></u-navbar>
		<view class="login_box">
			<view class="flex_box flex_row_center login_logo">
				<u-image width="180rpx" height="180rpx" radius="32rpx" :src="mainBaseUrl + '/assets/xcx/logo.png'"></u-image>
			</view>
			<view class="login_title">认证码设置</view>
			<u--form labelPosition="top" :model="form" :rules="rules" ref="uForm" :errorType="errorType"
				labelWidth="200rpx">
				<u-form-item label="认证码" prop="code" borderBottom>
					<u--input v-model="form.code" border="none" placeholder="请输入认证码"></u--input>
				</u-form-item>
				<view class="login_btn">
					<u-button throttleTime="1000" color="#0FBCF9" shape="circle" :customStyle="btnStyle" @click="submit" text="确认"></u-button>
				</view>
			</u--form>
		</view>
	</view>
</template>

<script>
	import { getBaseUrl } from '@/common/http.api.js';
	let that;
	export default {
		data() {
			return {
				form: {
					code: '',
				},
				errorType: "toast",
				rules: {
					code: [{
							type: 'string',
							required: true,
							message: '请输入您的认证码',
							trigger: ['blur', 'change']
						},
					],
				},
				btnStyle: {
					height: '88rpx'
				},
			}
		},
		onLoad() {
			that = this;
		},
		onReady() {
			that.$refs.uForm.setRules(that.rules);
		},
		methods: {
			submit() {
				that.$refs.uForm.validate().then(res => {
					getBaseUrl({params: that.form}).then(res=>{
						if(!res.data||res.data==''){
							that.$refs.uToast.show({
								type: "error",
								message: "该系统未认证成功",
							});
							return
						}
						let baseUrl = res.data.charAt(res.data.length - 1) === '/' ? res.data.substring(0,res.data.length - 1) : res.data;
						uni.$u.vuex("isAuth", true),uni.$u.vuex("baseUrl", res.data),uni.$u.vuex("uploadUrl", res.data+'/index/ajax/upload');
						uni.$u.http.setConfig((config) => {
						    /* config 为默认全局配置*/
						    config.baseURL = baseUrl; /* 根域名 */
						    return config
						})
						that.$refs.uToast.show({
							type: "success",
							message: "设置成功",
							complete(){
								that.$goUrl("/pages/home/index/index","tab");
							}
						});
					}).catch(err=>{
						uni.$u.toast(err.msg);
					});
				}).catch(errors => {

				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.Login {
		min-height: 100vh;
		background-color: #ffffff;

		.login_box {
			padding: 0 72rpx;

			.login_title {
				padding: 45rpx 0;
				font-size: 40rpx;
				color: #333333;
				font-weight: bold;
			}
			.login_btn{
				padding-top: 50rpx;
			}
		}
	}
</style>
